package Controller.Customer;


import Dto.Customer;
import Service.CustomerService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "addCustomer", value = "/addCustomer")
public class AddCustomer extends HttpServlet {
    private CustomerService customerService = new CustomerService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String company = request.getParameter("company");
        String name = request.getParameter("name");
        String phone = request.getParameter("phone");
        String emails = request.getParameter("email");
        String cooperate = request.getParameter("cooperate");
        Customer customer = new Customer();
        customer.setCompany(company);
        customer.setName(name);
        customer.setPhone(phone);
        customer.setEmail(emails);
        customer.setCooperate(cooperate);
        try {
            customerService.addCustomer(customer);
            request.getRequestDispatcher("/ListCustomer").forward(request, response);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}